package com.project2.service;

import com.project2.bean.po.MarketFeedback;
import com.project2.bean.po.MarketUser;
import com.project2.mapper.MarketFeedbackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @Author: MH
 * @Date: 2022-08-15 17:36
 * @Description: 意见反馈的具体实现
 */
@Service
public class WxFeedbackServiceImpl implements WxFeedbackService {

    @Autowired
    MarketFeedbackMapper marketFeedbackMapper;

    /**
    *@Author: MH
    *@date: 2022/8/15 20:01
    *@Description:根据前端返回的用户输入的返回信息,然后再拿到用户信息
     *            获得用户的名字和id,更新时间,然后插入即可
    */
    @Override
    public void submitInfo(MarketFeedback marketFeedback, HttpServletRequest request) {
        String header = request.getHeader("X-CskaoyanMarket-Token");
        MarketUser user = (MarketUser) request.getSession().getAttribute(header);
        Date date = new Date();
        marketFeedback.setAddTime(date);
        marketFeedback.setUpdateTime(date);
        marketFeedback.setUserId(user.getId());
        marketFeedback.setUsername(user.getUsername());
        marketFeedback.setDeleted(false);
        marketFeedbackMapper.insertSelective(marketFeedback);
    }
}
